package com.zhiyou100.blog.aciton.user;

import com.zhiyou100.blog.entity.PageBean;
import com.zhiyou100.blog.entity.Title;
import com.zhiyou100.blog.entity.User;
import com.zhiyou100.blog.service.TitleService;
import com.zhiyou100.blog.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author shkstart
 * @create 2021-10-25 15:53
 */
@WebServlet("/user/show")
public class UserShowServlet extends HttpServlet {
    private UserService service = new UserService();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*
         * 思路第一页展示用户信息
         * 第二页展示该用户的话题
         * */
        String uid = request.getParameter("uid");
        String pageNum = request.getParameter("pageNum");

        if (pageNum == null || "".equals(pageNum)) {
            pageNum = "1";
        }

        User user = service.getUserLvAndListFen(Integer.parseInt(uid));
        System.out.println("Shouser user = " + user);

        TitleService service = new TitleService();
        PageBean<Title> userPage = service.queryLIstTitlePagingByUid(Integer.parseInt(pageNum), Integer.parseInt(uid));

        request.setAttribute("Shouser", user);
        request.setAttribute("userPage", userPage);
        System.out.println("userPage = " + userPage);

        request.getRequestDispatcher("/index.jsp?pageName=view/user_show.jsp").forward(request, response);
    }
}
